package wangwenjun.phase2.concurrencypattern.activeobject.staticproxy.framework;

import lombok.extern.slf4j.Slf4j;
import wangwenjun.phase2.concurrencypattern.activeobject.staticproxy.OrderService;
import wangwenjun.phase2.concurrencypattern.future.Future;
import wangwenjun.phase2.concurrencypattern.future.FutureImpl;

import java.util.Map;

/**
 * @author ChangLiang
 * @date 2020/6/17
 */
@Slf4j
class OrderDetailsMessage extends OrderServiceMessage {

    public OrderDetailsMessage(Map<String, Object> params, OrderService orderService) {
        super(params,orderService);
    }

    @Override
    public void execute() {
        Future<String> futureServiceFutureImpl = orderService.findOrderDetails((Long) params.get("orderId"));
        log.info("Thread:{} FutureService#submit:{}",Thread.currentThread(),futureServiceFutureImpl.toString());
        FutureImpl<String> OrderServiceProxyFutureImpl = (FutureImpl<String>) params.get("future");
        try {
            // 挂起的是order-service-daemon-thread中的FutureService#FutureImpl#MUTEX
            String result = futureServiceFutureImpl.get();
            OrderServiceProxyFutureImpl.finish(result);
        } catch (InterruptedException e) {
            OrderServiceProxyFutureImpl.finish(null);
        }
    }
}
